*
* @file
*/
+use MediaWiki\Linker\LinkTarget;
/**
* Some internal bits split of from Skin.php. These functions are used
/**
* Get the appropriate HTML attributes to add to the "a" element of an interwiki link.
*
+ * @since 1.16.3
* @deprecated since 1.25
*
* @param string $title The title text for the link, URL-encoded (???) but
/**
* Get the appropriate HTML attributes to add to the "a" element of an internal link.
*
+ * @since 1.16.3
* @deprecated since 1.25
*
* @param string $title The title text for the link, URL-encoded (???) but
* Get the appropriate HTML attributes to add to the "a" element of an internal
* link, given the Title object for the page we want to link to.
*
+ * @since 1.16.3
* @deprecated since 1.25
*
* @param Title $nt
/**
* Common code for getLinkAttributesX functions
*
+ * @since 1.16.3
* @deprecated since 1.25
*
* @param string $title
/**
* Return the CSS colour of a known link
*
+ * @since 1.16.3
* @param Title $t
* @param int $threshold User defined threshold
* @return string CSS class
* @return string HTML <a> attribute
*/
public static function link(
- $target, $html = null, $customAttribs = array(), $query = array(), $options = array()
+ $target, $html = null, $customAttribs = [], $query = [], $options = []
) {
if ( !$target instanceof Title ) {
wfWarn( __METHOD__ . ': Requires $target to be a Title object.', 2 );
$ret = null;
if ( !Hooks::run( 'LinkBegin',
- array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) )
+ [ $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ] )
) {
return $ret;
}
}
}
- $oldquery = array();
+ $oldquery = [];
if ( in_array( "forcearticlepath", $options, true ) && $query ) {
$oldquery = $query;
- $query = array();
+ $query = [];
}
# Note: we want the href attribute first, for prettiness.
- $attribs = array( 'href' => self::linkUrl( $target, $query, $options ) );
+ $attribs = [ 'href' => self::linkUrl( $target, $query, $options ) ];
if ( in_array( 'forcearticlepath', $options, true ) && $oldquery ) {
$attribs['href'] = wfAppendQuery( $attribs['href'], $oldquery );
}
}
$ret = null;
- if ( Hooks::run( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) {
+ if ( Hooks::run( 'LinkEnd', [ $dummy, $target, $options, &$html, &$attribs, &$ret ] ) ) {
$ret = Html::rawElement( 'a', $attribs, $html );
}
/**
* Identical to link(), except $options defaults to 'known'.
+ * @since 1.16.3
* @see Linker::link
* @return string
*/
public static function linkKnown(
- $target, $html = null, $customAttribs = array(),
- $query = array(), $options = array( 'known', 'noclasses' )
+ $target, $html = null, $customAttribs = [],
+ $query = [], $options = [ 'known' ]
) {
return self::link( $target, $html, $customAttribs, $query, $options );
}
/**
* Returns the Url used to link to a Title
*
- * @param Title $target
+ * @param LinkTarget $target
* @param array $query Query parameters
* @param array $options
* @return string
*/
- private static function linkUrl( $target, $query, $options ) {
+ private static function linkUrl( LinkTarget $target, $query, $options ) {
# We don't want to include fragments for broken links, because they
# generally make no sense.
if ( in_array( 'broken', $options, true ) && $target->hasFragment() ) {
- $target = clone $target;
- $target->setFragment( '' );
+ $target = $target->createFragmentTarget( '' );
}
# If it's a broken link, add the appropriate query pieces, unless
# there's already an action specified, or unless 'edit' makes no sense
# (i.e., for a nonexistent special page).
if ( in_array( 'broken', $options, true ) && empty( $query['action'] )
- && !$target->isSpecialPage() ) {
+ && $target->getNamespace() !== NS_SPECIAL ) {
$query['action'] = 'edit';
$query['redlink'] = '1';
}
$proto = PROTO_RELATIVE;
}
- $ret = $target->getLinkURL( $query, false, $proto );
+ $title = Title::newFromLinkTarget( $target );
+ $ret = $title->getLinkURL( $query, false, $proto );
return $ret;
}
*/
private static function linkAttribs( $target, $attribs, $options ) {
global $wgUser;
- $defaults = array();
+ $defaults = [];
if ( !in_array( 'noclasses', $options, true ) ) {
# Now build the classes.
- $classes = array();
+ $classes = [];
if ( in_array( 'broken', $options, true ) ) {
$classes[] = 'new';
$classes[] = $colour; # mw-redirect or stub
}
}
- if ( $classes != array() ) {
+ if ( $classes != [] ) {
$defaults['class'] = implode( ' ', $classes );
}
}
# Finally, merge the custom attribs with the default ones, and iterate
# over that, deleting all "false" attributes.
- $ret = array();
+ $ret = [];
$merged = Sanitizer::mergeAttributes( $defaults, $attribs );
foreach ( $merged as $key => $val ) {
# A false value suppresses the attribute, and we don't want the
* same as the other make*LinkObj static functions, despite $query not
* being used.
*
+ * @since 1.16.3
* @param Title $nt
* @param string $html [optional]
* @param string $query [optional]
*/
public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
$ret = "<strong class=\"selflink\">{$prefix}{$html}</strong>{$trail}";
- if ( !Hooks::run( 'SelfLinkBegin', array( $nt, &$html, &$trail, &$prefix, &$ret ) ) ) {
+ if ( !Hooks::run( 'SelfLinkBegin', [ $nt, &$html, &$trail, &$prefix, &$ret ] ) ) {
return $ret;
}
}
/**
- * @param Title $title
- * @return Title
+ * @since 1.16.3
+ * @param LinkTarget $target
+ * @return LinkTarget|Title You will get back the same type you passed in, or a Title object
*/
- static function normaliseSpecialPage( Title $title ) {
- if ( $title->isSpecialPage() ) {
- list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
+ public static function normaliseSpecialPage( LinkTarget $target ) {
+ if ( $target->getNamespace() == NS_SPECIAL ) {
+ list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $target->getDBkey() );
if ( !$name ) {
- return $title;
+ return $target;
}
- $ret = SpecialPage::getTitleFor( $name, $subpage, $title->getFragment() );
+ $ret = SpecialPage::getTitleFor( $name, $subpage, $target->getFragment() );
return $ret;
} else {
- return $title;
+ return $target;
}
}
* Return the code for images which were added via external links,
* via Parser::maybeMakeExternalImage().
*
+ * @since 1.16.3
* @param string $url
* @param string $alt
*
$alt = self::fnamePart( $url );
}
$img = '';
- $success = Hooks::run( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
+ $success = Hooks::run( 'LinkerMakeExternalImage', [ &$url, &$alt, &$img ] );
if ( !$success ) {
wfDebug( "Hook LinkerMakeExternalImage changed the output of external image "
. "with url {$url} and alt text {$alt} to {$img}\n", true );
return $img;
}
return Html::element( 'img',
- array(
+ [
'src' => $url,
- 'alt' => $alt ) );
+ 'alt' => $alt ] );
}
/**
* @return string HTML for an image, with links, wrappers, etc.
*/
public static function makeImageLink( Parser $parser, Title $title,
- $file, $frameParams = array(), $handlerParams = array(), $time = false,
+ $file, $frameParams = [], $handlerParams = [], $time = false,
$query = "", $widthOption = null
) {
$res = null;
$dummy = new DummyLinker;
- if ( !Hooks::run( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
- &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
+ if ( !Hooks::run( 'ImageBeforeProduceHTML', [ &$dummy, &$title,
+ &$file, &$frameParams, &$handlerParams, &$time, &$res ] ) ) {
return $res;
}
$s = self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
} else {
self::processResponsiveImages( $file, $thumb, $hp );
- $params = array(
+ $params = [
'alt' => $fp['alt'],
'title' => $fp['title'],
'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false,
- 'img-class' => $fp['class'] );
+ 'img-class' => $fp['class'] ];
if ( isset( $fp['border'] ) ) {
$params['img-class'] .= ( $params['img-class'] !== '' ? ' ' : '' ) . 'thumbborder';
}
* @return array
*/
private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) {
- $mtoParams = array();
+ $mtoParams = [];
if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
$mtoParams['custom-url-link'] = $frameParams['link-url'];
if ( isset( $frameParams['link-target'] ) ) {
* @return string
*/
public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
- $align = 'right', $params = array(), $framed = false, $manualthumb = ""
+ $align = 'right', $params = [], $framed = false, $manualthumb = ""
) {
- $frameParams = array(
+ $frameParams = [
'alt' => $alt,
'caption' => $label,
'align' => $align
- );
+ ];
if ( $framed ) {
$frameParams['framed'] = true;
}
* @param string $query
* @return string
*/
- public static function makeThumbLink2( Title $title, $file, $frameParams = array(),
- $handlerParams = array(), $time = false, $query = ""
+ public static function makeThumbLink2( Title $title, $file, $frameParams = [],
+ $handlerParams = [], $time = false, $query = ""
) {
$exists = $file && $file->exists();
# zoom icon still needs it, so we make a unique query for it. See bug 14771
$url = $title->getLocalURL( $query );
if ( $page ) {
- $url = wfAppendQuery( $url, array( 'page' => $page ) );
+ $url = wfAppendQuery( $url, [ 'page' => $page ] );
}
if ( $manualthumb
&& !isset( $fp['link-title'] )
if ( !$noscale && !$manualthumb ) {
self::processResponsiveImages( $file, $thumb, $hp );
}
- $params = array(
+ $params = [
'alt' => $fp['alt'],
'title' => $fp['title'],
'img-class' => ( isset( $fp['class'] ) && $fp['class'] !== ''
? $fp['class'] . ' '
: '' ) . 'thumbimage'
- );
+ ];
$params = self::getImageLinkMTOParams( $fp, $query ) + $params;
$s .= $thumb->toHtml( $params );
if ( isset( $fp['framed'] ) ) {
$zoomIcon = "";
} else {
- $zoomIcon = Html::rawElement( 'div', array( 'class' => 'magnify' ),
- Html::rawElement( 'a', array(
+ $zoomIcon = Html::rawElement( 'div', [ 'class' => 'magnify' ],
+ Html::rawElement( 'a', [
'href' => $url,
'class' => 'internal',
- 'title' => wfMessage( 'thumbnail-more' )->text() ),
+ 'title' => wfMessage( 'thumbnail-more' )->text() ],
"" ) );
}
}
/**
* Make a "broken" link to an image
*
+ * @since 1.16.3
* @param Title $title
* @param string $label Link label (plain text)
* @param string $query Query string
$redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
if ( $redir ) {
- return self::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
+ // We already know it's a redirect, so mark it
+ // accordingly
+ return self::link(
+ $title,
+ $encLabel,
+ [ 'class' => 'mw-redirect' ],
+ wfCgiToArray( $query ),
+ [ 'known', 'noclasses' ]
+ );
}
$href = self::getUploadUrl( $title, $query );
$encLabel . '</a>';
}
- return self::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
+ return self::link( $title, $encLabel, [], wfCgiToArray( $query ), [ 'known', 'noclasses' ] );
}
/**
* Get the URL to upload a certain file
*
+ * @since 1.16.3
* @param Title $destFile Title object of the file to upload
* @param string $query Urlencoded query string to prepend
* @return string Urlencoded URL
/**
* Create a direct link to a given uploaded file.
*
+ * @since 1.16.3
* @param Title $title
* @param string $html Pre-sanitized HTML
* @param string $time MW timestamp of file creation time
* @return string HTML
*/
public static function makeMediaLinkObj( $title, $html = '', $time = false ) {
- $img = wfFindFile( $title, array( 'time' => $time ) );
+ $img = wfFindFile( $title, [ 'time' => $time ] );
return self::makeMediaLinkFile( $title, $img, $html );
}
* Create a direct link to a given uploaded file.
* This will make a broken link if $file is false.
*
+ * @since 1.16.3
* @param Title $title
* @param File|bool $file File object or false
* @param string $html Pre-sanitized HTML
*/
public static function makeMediaLinkFile( Title $title, $file, $html = '' ) {
if ( $file && $file->exists() ) {
- $url = $file->getURL();
+ $url = $file->getUrl();
$class = 'internal';
} else {
$url = self::getUploadUrl( $title );
}
$ret = '';
- $attribs = array(
+ $attribs = [
'href' => $url,
'class' => $class,
'title' => $alt
- );
+ ];
if ( !Hooks::run( 'LinkerMakeMediaLinkFile',
- array( $title, $file, &$html, &$attribs, &$ret ) ) ) {
+ [ $title, $file, &$html, &$attribs, &$ret ] ) ) {
wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link "
. "with url {$url} and text {$html} to {$ret}\n", true );
return $ret;
* a message key from the link text.
* Usage example: Linker::specialLink( 'Recentchanges' )
*
+ * @since 1.16.3
* @param string $name
* @param string $key
* @return string
/**
* Make an external link
+ * @since 1.16.3. $title added in 1.21
* @param string $url URL to link to
* @param string $text Text of link
* @param bool $escape Do we escape the link text?
* @return string
*/
public static function makeExternalLink( $url, $text, $escape = true,
- $linktype = '', $attribs = array(), $title = null
+ $linktype = '', $attribs = [], $title = null
) {
global $wgTitle;
$class = "external";
if ( !$title ) {
$title = $wgTitle;
}
- $attribs['rel'] = Parser::getExternalLinkRel( $url, $title );
+ $newRel = Parser::getExternalLinkRel( $url, $title );
+ if ( !isset( $attribs['rel'] ) || $attribs['rel'] === '' ) {
+ $attribs['rel'] = $newRel;
+ } elseif ( $newRel !== '' ) {
+ // Merge the rel attributes.
+ $newRels = explode( ' ', $newRel );
+ $oldRels = explode( ' ', $attribs['rel'] );
+ $combined = array_unique( array_merge( $newRels, $oldRels ) );
+ $attribs['rel'] = implode( ' ', $combined );
+ }
$link = '';
$success = Hooks::run( 'LinkerMakeExternalLink',
- array( &$url, &$text, &$link, &$attribs, $linktype ) );
+ [ &$url, &$text, &$link, &$attribs, $linktype ] );
if ( !$success ) {
wfDebug( "Hook LinkerMakeExternalLink changed the output of link "
. "with url {$url} and text {$text} to {$link}\n", true );
* @param string $userName User name in database.
* @param string $altUserName Text to display instead of the user name (optional)
* @return string HTML fragment
- * @since 1.19 Method exists for a long time. $altUserName was added in 1.19.
+ * @since 1.16.3. $altUserName was added in 1.19.
*/
public static function userLink( $userId, $userName, $altUserName = false ) {
$classes = 'mw-userlink';
return self::link(
$page,
htmlspecialchars( $altUserName !== false ? $altUserName : $userName ),
- array( 'class' => $classes )
+ [ 'class' => $classes ]
);
}
/**
* Generate standard user tool links (talk, contributions, block link, etc.)
*
+ * @since 1.16.3
* @param int $userId User identifier
* @param string $userText User name or IP address
* @param bool $redContribsWhenNoEdits Should the contributions link be
$blockable = !( $flags & self::TOOL_LINKS_NOBLOCK );
$addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
- $items = array();
+ $items = [];
if ( $talkable ) {
$items[] = self::userTalkLink( $userId, $userText );
}
if ( $userId ) {
// check if the user has an edit
- $attribs = array();
+ $attribs = [];
if ( $redContribsWhenNoEdits ) {
if ( intval( $edits ) === 0 && $edits !== 0 ) {
$user = User::newFromId( $userId );
$items[] = self::emailLink( $userId, $userText );
}
- Hooks::run( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
+ Hooks::run( 'UserToolLinksEdit', [ $userId, $userText, &$items ] );
if ( $items ) {
return wfMessage( 'word-separator' )->escaped()
/**
* Alias for userToolLinks( $userId, $userText, true );
+ * @since 1.16.3
* @param int $userId User identifier
* @param string $userText User name or IP address
* @param int $edits User edit count (optional, for performance)
}
/**
+ * @since 1.16.3
* @param int $userId User id in database.
* @param string $userText User name in database.
* @return string HTML fragment with user talk link
}
/**
+ * @since 1.16.3
* @param int $userId Userid
* @param string $userText User name in database.
* @return string HTML fragment with block link
/**
* Generate a user link if the current user is allowed to view it
+ * @since 1.16.3
* @param Revision $rev
* @param bool $isPublic Show only if all users can see it
* @return string HTML fragment
/**
* Generate a user tool link cluster if the current user is allowed to view it
+ * @since 1.16.3
* @param Revision $rev
* @param bool $isPublic Show only if all users can see it
* @return string HTML
* auto-generated comments (from section editing) and formats [[wikilinks]].
*
* @author Erik Moeller <moeller@scireview.de>
+ * @since 1.16.3. $wikiId added in 1.26
*
* Note: there's not always a title to pass to this function.
* Since you can't set a default parameter for a reference, I've turned it
global $wgLang;
// Ensure all match positions are defined
- $match += array( '', '', '', '' );
+ $match += [ '', '', '', '' ];
$pre = $match[1] !== '';
$auto = $match[2];
Hooks::run(
'FormatAutocomments',
- array( &$comment, $pre, $auto, $post, $title, $local, $wikiId )
+ [ &$comment, $pre, $auto, $post, $title, $local, $wikiId ]
);
if ( $comment === null ) {
* Formats wiki links and media links in text; all other wiki formatting
* is ignored
*
+ * @since 1.16.3. $wikiId added in 1.26
* @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
+ *
* @param string $comment Text to format links in. WARNING! Since the output of this
* function is html, $comment must be sanitized for use as html. You probably want
* to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling
if ( strpos( $match[1], '%' ) !== false ) {
$match[1] = strtr(
rawurldecode( $match[1] ),
- array( '<' => '<', '>' => '>' )
+ [ '<' => '<', '>' => '>' ]
);
}
} else {
$text = $match[1];
}
- $submatch = array();
+ $submatch = [];
$thelink = null;
if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
# Media link; trail not supported.
}
} else {
# Other kind of link
- if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) {
- $trail = $submatch[1];
- } else {
- $trail = "";
- }
- $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
+ # Make sure its target is non-empty
if ( isset( $match[1][0] ) && $match[1][0] == ':' ) {
$match[1] = substr( $match[1], 1 );
}
- list( $inside, $trail ) = Linker::splitTrail( $trail );
-
- $linkText = $text;
- $linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText );
-
- $target = Title::newFromText( $linkTarget );
- if ( $target ) {
- if ( $target->getText() == '' && !$target->isExternal()
- && !$local && $title
- ) {
- $newTarget = clone $title;
- $newTarget->setFragment( '#' . $target->getFragment() );
- $target = $newTarget;
+ if ( $match[1] !== false && $match[1] !== '' ) {
+ if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) {
+ $trail = $submatch[1];
+ } else {
+ $trail = "";
}
+ $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
+ list( $inside, $trail ) = Linker::splitTrail( $trail );
+
+ $linkText = $text;
+ $linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText );
+
+ $target = Title::newFromText( $linkTarget );
+ if ( $target ) {
+ if ( $target->getText() == '' && !$target->isExternal()
+ && !$local && $title
+ ) {
+ $newTarget = clone $title;
+ $newTarget->setFragment( '#' . $target->getFragment() );
+ $target = $newTarget;
+ }
- $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail;
+ $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail;
+ }
}
}
if ( $thelink ) {
* @return string HTML link
*/
public static function makeCommentLink(
- Title $title, $text, $wikiId = null, $options = array()
+ Title $title, $text, $wikiId = null, $options = []
) {
if ( $wikiId !== null && !$title->isExternal() ) {
$link = Linker::makeExternalLink(
/* escape = */ false // Already escaped
);
} else {
- $link = Linker::link( $title, $text, array(), array(), $options );
+ $link = Linker::link( $title, $text, [], [], $options );
}
return $link;
# Look at the first character
if ( $target != '' && $target[0] === '/' ) {
# / at end means we don't want the slash to be shown
- $m = array();
+ $m = [];
$trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
if ( $trailingSlashes ) {
$noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
* Wrap a comment in standard punctuation and formatting if
* it's non-empty, otherwise return empty string.
*
+ * @since 1.16.3. $wikiId added in 1.26
* @param string $comment
* @param Title|null $title Title object (to generate link to section in autocomment) or null
* @param bool $local Whether section links should refer to local page
* Wrap and format the given revision's comment block, if the current
* user is allowed to view it.
*
+ * @since 1.16.3
* @param Revision $rev
* @param bool $local Whether section links should refer to local page
* @param bool $isPublic Show only if all users can see it
}
/**
+ * @since 1.16.3
* @param int $size
* @return string
*/
/**
* Add another level to the Table of Contents
*
+ * @since 1.16.3
* @return string
*/
public static function tocIndent() {
/**
* Finish one or more sublevels on the Table of Contents
*
+ * @since 1.16.3
* @param int $level
* @return string
*/
/**
* parameter level defines if we are on an indentation level
*
+ * @since 1.16.3
* @param string $anchor
* @param string $tocline
* @param string $tocnumber
* End a Table Of Contents line.
* tocUnindent() will be used instead if we're ending a line below
* the new level.
+ * @since 1.16.3
* @return string
*/
public static function tocLineEnd() {
/**
* Wraps the TOC in a table and provides the hide/collapse javascript.
*
+ * @since 1.16.3
* @param string $toc Html of the Table Of Contents
* @param string|Language|bool $lang Language for the toc title, defaults to user language
* @return string Full html of the TOC
/**
* Generate a table of contents from a section tree.
*
+ * @since 1.16.3. $lang added in 1.17
* @param array $tree Return value of ParserOutput::getSections()
* @param string|Language|bool $lang Language for the toc title, defaults to user language
* @return string HTML fragment
/**
* Create a headline for content
*
+ * @since 1.16.3
* @param int $level The level of the headline (1-6)
* @param string $attribs Any attributes for the headline, starting with
* a space and ending with '>'
$regex = $wgContLang->linkTrail();
$inside = '';
if ( $trail !== '' ) {
- $m = array();
+ $m = [];
if ( preg_match( $regex, $trail, $m ) ) {
$inside = $m[1];
$trail = $m[2];
}
}
- return array( $inside, $trail );
+ return [ $inside, $trail ];
}
/**
* work if $wgShowRollbackEditCount is disabled, so this can only function
* as an additional check.
*
- * If the option noBrackets is set the rollback link wont be enclosed in []
+ * If the option noBrackets is set the rollback link wont be enclosed in "[]".
+ *
+ * See the "mediawiki.page.rollback" module for the client-side handling of this link.
+ *
+ * @since 1.16.3. $context added in 1.20. $options added in 1.21
*
* @param Revision $rev
* @param IContextSource $context Context to use or null for the main context.
* @return string
*/
public static function generateRollback( $rev, IContextSource $context = null,
- $options = array( 'verify' )
+ $options = [ 'verify' ]
) {
if ( $context === null ) {
$context = RequestContext::getMain();
$inner = $context->msg( 'brackets' )->rawParams( $inner )->escaped();
}
+ $context->getOutput()->addModules( 'mediawiki.page.rollback' );
+
return '<span class="mw-rollback-link">' . $inner . '</span>';
}
// Up to the value of $wgShowRollbackEditCount revisions are counted
$res = $dbr->select(
'revision',
- array( 'rev_user_text', 'rev_deleted' ),
+ [ 'rev_user_text', 'rev_deleted' ],
// $rev->getPage() returns null sometimes
- array( 'rev_page' => $rev->getTitle()->getArticleID() ),
+ [ 'rev_page' => $rev->getTitle()->getArticleID() ],
__METHOD__,
- array(
- 'USE INDEX' => array( 'revision' => 'page_timestamp' ),
+ [
+ 'USE INDEX' => [ 'revision' => 'page_timestamp' ],
'ORDER BY' => 'rev_timestamp DESC',
'LIMIT' => $wgShowRollbackEditCount + 1
- )
+ ]
);
$editCount = 0;
/**
* Build a raw rollback link, useful for collections of "tool" links
*
+ * @since 1.16.3. $context added in 1.20. $editCount added in 1.21
* @param Revision $rev
* @param IContextSource|null $context Context to use or null for the main context.
* @param int $editCount Number of edits that would be reverted
global $wgShowRollbackEditCount, $wgMiserMode;
// To config which pages are affected by miser mode
- $disableRollbackEditCountSpecialPage = array( 'Recentchanges', 'Watchlist' );
+ $disableRollbackEditCountSpecialPage = [ 'Recentchanges', 'Watchlist' ];
if ( $context === null ) {
$context = RequestContext::getMain();
}
$title = $rev->getTitle();
- $query = array(
+ $query = [
'action' => 'rollback',
'from' => $rev->getUserText(),
- 'token' => $context->getUser()->getEditToken( array(
- $title->getPrefixedText(),
- $rev->getUserText()
- ) ),
- );
+ ];
+ $attrs = [
+ 'data-mw' => 'interface',
+ 'title' => $context->msg( 'tooltip-rollback' )->text(),
+ ];
+ $options = [ 'known', 'noclasses' ];
+
if ( $context->getRequest()->getBool( 'bot' ) ) {
$query['bot'] = '1';
$query['hidediff'] = '1'; // bug 15999
}
if ( $editCount > $wgShowRollbackEditCount ) {
- $editCount_output = $context->msg( 'rollbacklinkcount-morethan' )
+ $html = $context->msg( 'rollbacklinkcount-morethan' )
->numParams( $wgShowRollbackEditCount )->parse();
} else {
- $editCount_output = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
+ $html = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
}
- return self::link(
- $title,
- $editCount_output,
- array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
- $query,
- array( 'known', 'noclasses' )
- );
+ return self::link( $title, $html, $attrs, $query, $options );
} else {
- return self::link(
- $title,
- $context->msg( 'rollbacklink' )->escaped(),
- array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
- $query,
- array( 'known', 'noclasses' )
- );
+ $html = $context->msg( 'rollbacklink' )->escaped();
+ return self::link( $title, $html, $attrs, $query, $options );
}
}
* directly paste it in as the link (escaping needs to be done manually).
* Finally, if $more is a Message, call toString().
*
+ * @since 1.16.3. $more added in 1.21
* @param Title[] $templates Array of templates
* @param bool $preview Whether this is for a preview
* @param bool $section Whether this is for a section edit
if ( $restrictions ) {
// Check backwards-compatible messages
$msg = null;
- if ( $restrictions === array( 'sysop' ) ) {
+ if ( $restrictions === [ 'sysop' ] ) {
$msg = wfMessage( 'template-protected' );
- } elseif ( $restrictions === array( 'autoconfirmed' ) ) {
+ } elseif ( $restrictions === [ 'autoconfirmed' ] ) {
$msg = wfMessage( 'template-semiprotected' );
}
if ( $msg && !$msg->isDisabled() ) {
} else {
// Construct the message from restriction-level-*
// e.g. restriction-level-sysop, restriction-level-autoconfirmed
- $msgs = array();
+ $msgs = [];
foreach ( $restrictions as $r ) {
$msgs[] = wfMessage( "restriction-level-$r" )->parse();
}
$editLink = self::link(
$titleObj,
wfMessage( 'editlink' )->escaped(),
- array(),
- array( 'action' => 'edit' )
+ [],
+ [ 'action' => 'edit' ]
);
} else {
$editLink = self::link(
$titleObj,
wfMessage( 'viewsourcelink' )->escaped(),
- array(),
- array( 'action' => 'edit' )
+ [],
+ [ 'action' => 'edit' ]
);
}
$outText .= '<li>' . self::link( $titleObj )
/**
* Returns HTML for the "hidden categories on this page" list.
*
+ * @since 1.16.3
* @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
* or similar
* @return string HTML output
foreach ( $hiddencats as $titleObj ) {
# If it's hidden, it must exist - no need to check with a LinkBatch
$outText .= '<li>'
- . self::link( $titleObj, null, array(), array(), 'known' )
+ . self::link( $titleObj, null, [], [], 'known' )
. "</li>\n";
}
$outText .= '</ul>';
* Format a size in bytes for output, using an appropriate
* unit (B, KB, MB or GB) according to the magnitude in question
*
+ * @since 1.16.3
* @param int $size Size to format
* @return string
*/
* isn't always, because sometimes the accesskey needs to go on a different
* element than the id, for reverse-compatibility, etc.)
*
+ * @since 1.16.3 $msgParams added in 1.27
* @param string $name Id of the element, minus prefixes.
* @param string|null $options Null or the string 'withaccess' to add an access-
* key hint
* @return string Contents of the title attribute (which you must HTML-
* escape), or false for no title attribute
*/
- public static function titleAttrib( $name, $options = null, array $msgParams = array() ) {
+ public static function titleAttrib( $name, $options = null, array $msgParams = [] ) {
$message = wfMessage( "tooltip-$name", $msgParams );
if ( !$message->exists() ) {
$tooltip = false;
* the id but isn't always, because sometimes the accesskey needs to go on
* a different element than the id, for reverse-compatibility, etc.)
*
+ * @since 1.16.3
* @param string $name Id of the element, minus prefixes.
* @return string Contents of the accesskey attribute (which you must HTML-
* escape), or false for no accesskey attribute
if ( $rev->getId() ) {
// RevDelete links using revision ID are stable across
// page deletion and undeletion; use when possible.
- $query = array(
+ $query = [
'type' => 'revision',
'target' => $title->getPrefixedDBkey(),
'ids' => $rev->getId()
- );
+ ];
} else {
// Older deleted entries didn't save a revision ID.
// We have to refer to these by timestamp, ick!
- $query = array(
+ $query = [
'type' => 'archive',
'target' => $title->getPrefixedDBkey(),
'ids' => $rev->getTimestamp()
- );
+ ];
}
return Linker::revDeleteLink( $query,
$rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
* @return string HTML "<a>" link to Special:Revisiondelete, wrapped in a
* span to allow for customization of appearance with CSS
*/
- public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
+ public static function revDeleteLink( $query = [], $restricted = false, $delete = true ) {
$sp = SpecialPage::getTitleFor( 'Revisiondelete' );
$msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted';
$html = wfMessage( $msgKey )->escaped();
$tag = $restricted ? 'strong' : 'span';
- $link = self::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) );
+ $link = self::link( $sp, $html, [], $query, [ 'known', 'noclasses' ] );
return Xml::tags(
$tag,
- array( 'class' => 'mw-revdelundel-link' ),
+ [ 'class' => 'mw-revdelundel-link' ],
wfMessage( 'parentheses' )->rawParams( $link )->escaped()
);
}
/**
* Creates a dead (show/hide) link for deleting revisions/log entries
*
+ * @since 1.16.3
* @param bool $delete Set to true to use (show/hide) rather than (show)
*
* @return string HTML text wrapped in a span to allow for customization
$msgKey = $delete ? 'rev-delundel' : 'rev-showdeleted';
$html = wfMessage( $msgKey )->escaped();
$htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped();
- return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), $htmlParentheses );
+ return Xml::tags( 'span', [ 'class' => 'mw-revdelundel-link' ], $htmlParentheses );
}
/* Deprecated methods */
/**
* Returns the attributes for the tooltip and access key.
*
+ * @since 1.16.3. $msgParams introduced in 1.27
* @param string $name
* @param array $msgParams Params for constructing the message
*
* @return array
*/
- public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = array() ) {
+ public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = [] ) {
# @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
# no attribute" instead of "output '' as value for attribute", this
# would be three lines.
- $attribs = array(
+ $attribs = [
'title' => self::titleAttrib( $name, 'withaccess', $msgParams ),
'accesskey' => self::accesskey( $name )
- );
+ ];
if ( $attribs['title'] === false ) {
unset( $attribs['title'] );
}
/**
* Returns raw bits of HTML, use titleAttrib()
+ * @since 1.16.3
* @param string $name
* @param array|null $options
* @return null|string
if ( $tooltip === false ) {
return '';
}
- return Xml::expandAttributes( array(
+ return Xml::expandAttributes( [
'title' => $tooltip
- ) );
+ ] );
}
}
-/**
- * @since 1.18
- */
-class DummyLinker {
-
- /**
- * Use PHP's magic __call handler to transform instance calls to a dummy instance
- * into static calls to the new Linker for backwards compatibility.
- *
- * @param string $fname Name of called method
- * @param array $args Arguments to the method
- * @return mixed
- */
- public function __call( $fname, $args ) {
- return call_user_func_array( array( 'Linker', $fname ), $args );
- }
-}